package com.learn.use.myreconsituteproject.register;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.learn.use.myreconsituteproject.R;
import com.learn.use.myreconsituteproject.login.widget.LoginActivity;
import com.learn.use.myreconsituteproject.mvp.BaseActivity;
import com.learn.use.myreconsituteproject.mvp.codebean.CodeBean;
import com.learn.use.myreconsituteproject.register.bean.RegisterNextBean;
import com.learn.use.myreconsituteproject.register.presenter.RgDataPresenter;
import com.learn.use.myreconsituteproject.register.view.RegisterView;
import com.learn.use.myreconsituteproject.util.SharedPreferencesUtil;
import com.learn.use.myreconsituteproject.util.ViewUtil;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by 聪明一只哈 on 2018/9/12.
 * Time: 2018/9/12  10:28
 */
public class RegisterActivity extends BaseActivity<RegisterView, RgDataPresenter<RegisterView>> implements RegisterView{


    @BindView(R.id.et_user_register_inviter_code_num)
    EditText etUserRegisterInviterCodeNum;
    @BindView(R.id.et_user_register_cell_num)
    EditText etUserRegisterCellNum;
    @BindView(R.id.et_user_register_check_code)
    EditText etUserRegisterCheckCode;
    @BindView(R.id.bt_user_register_send_check_code)
    Button btUserRegisterSendCheckCode;
    @BindView(R.id.et_user_register_pwd)
    EditText etUserRegisterPwd;
    @BindView(R.id.bt_user_register)
    Button btUserRegister;
    private String ase_simple;
    private String count_num;
    private String pass;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ViewUtil.initSystemBar(this, R.color.system_bar_bg);
        setContentView(R.layout.activity_user_register);
        ButterKnife.bind(this);
        ase_simple = SharedPreferencesUtil.getString(this, "ase_simple", "");

    }

    @Override
    protected RgDataPresenter<RegisterView> creatPresenter() {
        return new RgDataPresenter<>();
    }


    @OnClick({R.id.bt_user_register_send_check_code, R.id.bt_user_register})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.bt_user_register_send_check_code:
                String num = etUserRegisterCellNum.getText().toString().trim();
                mPresenter.getRecongCode(ase_simple,num);
                break;
            case R.id.bt_user_register:
                count_num = etUserRegisterCellNum.getText().toString().trim();
                String check_code = etUserRegisterCheckCode.getText().toString().trim();
                pass = etUserRegisterPwd.getText().toString().trim();
                mPresenter.getRegisteredData(this, count_num, pass,check_code,ase_simple);

                break;
        }
    }

    @Override
    public void showProgress() {

    }

    @Override
    public void dissProgress() {

    }

    @Override
    public void RegisteDatasSuccess(RegisterNextBean registerNextBean) {
        switch (registerNextBean.getCode()) {
            case 500:
            case 501:
            case 502:
            case 503:
            case 504:
                Toast.makeText(RegisterActivity.this, registerNextBean.getMess(), Toast.LENGTH_SHORT).show();
                break;
            case 200:
                //保存自己账户的唯一Id
                String data_id = registerNextBean.getData_id();
                SharedPreferencesUtil.saveString(RegisterActivity.this, "App_Only_Id", data_id);
                Toast.makeText(RegisterActivity.this, registerNextBean.getMess(), Toast.LENGTH_SHORT).show();
                //传过去手机号,和密码
                Intent intent = new Intent(RegisterActivity.this, LoginActivity.class);
                //手机号
                intent.putExtra("user_regist_and_fogt_cell_reset", count_num);
                intent.putExtra("user_regis_pwd", pass);
                startActivity(intent);
                finish();
                break;

            default:

                break;
        }


    }

    @Override
    public void RegisteDatasFiled(String beanMessage) {
        Toast.makeText(RegisterActivity.this, ""+beanMessage, Toast.LENGTH_SHORT).show();

    }

    @Override
    public void getCodeData(CodeBean codeBean) {
        Toast.makeText(RegisterActivity.this, ""+codeBean.getMsg(), Toast.LENGTH_SHORT).show();

    }

    @Override
    public void getCodeError(String errormessage) {
        Toast.makeText(RegisterActivity.this, ""+errormessage, Toast.LENGTH_SHORT).show();
    }
}
